package jt.classic.system.tablequery.impl;

import jt.classic.system.AbstractIBigObject;
import jt.classic.system.tablequery.TableQuery;

import org.limp.basework.Column;

import org.limp.mine.StringTool;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 表查询管理类
 *
 * @author mido
 *
 */
public class TableQueryImpl extends AbstractIBigObject implements TableQuery {
    private String defaultlist;
    private String purview;
    private String purviewRole;
    private String desc;
    private String jsurl;
    private String cssurl;
    private String showchk;
    private String export;
    private List queryItems;
    private List relateItems;
    private List orderbyItems;
    private List restraintItems;
    private List resultItems;
    private List resultAnnexItems;
    private List tables;

    public boolean idefaultlist() {
        return (this.defaultlist == null) || !this.defaultlist.equals("-1");
    }

    public String ipurview() {
        return this.purview;
    }

    public String ipurviewRole() {
        return this.purviewRole;
    }

    public String ijsurl() {
        // TODO Auto-generated method stub
        return this.jsurl;
    }

    public String icssurl() {
        // TODO Auto-generated method stub
        return this.cssurl;
    }

    public String idesc() {
        // TODO Auto-generated method stub
        return this.desc;
    }

    public List iqueryItems() {
        // TODO Auto-generated method stub
        return this.queryItems;
    }

    public List irelateItems() {
        return this.relateItems;
    }

    public List iorderbyItems() {
        return this.orderbyItems;
    }

    public List irestraintItems() {
        // TODO Auto-generated method stub
        return this.restraintItems;
    }

    public List iresultItems() {
        // TODO Auto-generated method stub
        return this.resultItems;
    }

    public List iresultAnnexItems() {
        return this.resultAnnexItems;
    }

    public List itables() {
        // TODO Auto-generated method stub
        return this.tables;
    }

    public boolean ishowchk() {
        return (this.showchk != null) && this.showchk.equals("1");
    }

    public String iexport() {
        return this.export;
    }

    public void reload(Map map) {
        if (map != null) {
            this.info = map;
        }

        this.bigoid = (String) this.info.get("id");
        this.bigoname = (String) this.info.get("name");
        this.desc = (String) this.info.get("desc");
        this.jsurl = (String) this.info.get("jsurl");
        this.cssurl = (String) this.info.get("cssurl");
        this.export = StringTool.checkString(this.info.get("export"), "");
        this.queryItems = (List) this.info.get("queryItems");
        this.relateItems = (List) this.info.get("relateItems");
        this.orderbyItems = (List) this.info.get("orderbyItems");
        this.resultItems = (List) this.info.get("resultItems");

        if ((this.resultItems != null) && !this.resultItems.isEmpty()) {
            this.resultAnnexItems = new ArrayList();

            for (int i = 0; i < this.resultItems.size(); i++) {
                Map temp = (Map) this.resultItems.get(i);

                String alien = (String) temp.get("alien");
                Column column = (Column) temp.get("column");

                if (!alien.equals("1") && column.isAnnex()) {
                    this.resultAnnexItems.add(new HashMap(temp));
                }
            }
        }

        this.restraintItems = (List) this.info.get("restraintItems");
        this.tables = (List) this.info.get("tables");
        this.showchk = (String) this.info.get("showchk");
        this.purview = (String) this.info.get("purview");
        this.purviewRole = (String) this.info.get("purivewRole");
        this.defaultlist = (String) this.info.get("defaultlist");
    }
}
